package com.bw.base.net

import androidx.appcompat.app.WindowDecorActionBar.TabImpl
import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

object RetrofitUtils {
    fun getOkHttpClient():OkHttpClient{
        return OkHttpClient.Builder()
            .connectTimeout(5,TimeUnit.SECONDS)
            .readTimeout(5,TimeUnit.SECONDS)
            .writeTimeout(5,TimeUnit.SECONDS)
            .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
            .addInterceptor {
                var request = it.request().newBuilder()
                    .addHeader("accessId","25d9be915bd2451ca1ab3926158b541c")
                    .addHeader("token",SPUtils.getInstance().getString("token")).build()
                it.proceed(request)
            }
            .build()
    }
    fun getRetrofit():Retrofit{
        return Retrofit.Builder()
            .baseUrl(Const.BASE_URL)
            .client(getOkHttpClient())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
    }
}